package main

import (
	"fmt"
	"test-go/day6"
	"time"
)

func main() {
	//go day6.GetOff()
	//day6.GetOn()

	//go func() {
	//	for i := 0; i < 3; i++ {
	//		fmt.Println("左手画圆")
	//		time.Sleep(1 * time.Second)
	//	}
	//
	//}()
	//
	//for i := 0; i < 3; i++ {
	//	fmt.Println("右手画方")
	//	time.Sleep(1 * time.Second)
	//}

	//

	//c1 := make(chan string)
	//c2 := make(chan interface{})
	//
	//go t2(c1)
	//go t3(c1, c2)
	//driver(c2)

	//test_select()
	//time.Sleep(10 * time.Second)

	day6.Test_lock()
}

func t1(cl chan<- interface{}) {
	for i := 0; i < 3; i++ {
		cl <- i
		fmt.Println("发送信息 ", i)
		time.Sleep(1 * time.Second)
	}
}

func t2(cl chan<- string) {
	cl <- "点火"
	close(cl)
}

func t3(c1 <-chan string, c2 chan<- interface{}) {
	data := <-c1
	c2 <- data + "启动"
	close(c2)
}

func driver(c1 <-chan interface{}) {
	for data := range c1 {
		fmt.Println(data, " 开始触发")
	}
}

func test_select() {

	c1 := make(chan int)
	c2 := make(chan int)

	go func() {
		fmt.Println("go start")
		v := 1
		c1 <- v
		v2 := <-c2
		fmt.Println(v, v2)
		time.Sleep(10 * time.Second)
	}()

	v := 2
	var v2 int
	select {
	case c2 <- v:

	case v2 = <-c1:
	}
	fmt.Println(v, v2)
}
